/**
 * 与原生 App 套壳交互
 */
import { getLogger } from '@gnlab/utils'
import config from '@/config'
import services from '@/services'

const logger = getLogger('app-native')

const inNative = location.href.includes('native=1')

export const native = {
  inNative,

  goSetNetwork() {
    logger.info('进入网络设置页')
  },

  goAccount() {
    if (inNative) {
      logger.info('进入账号信息页')
    } else {
      const account = services.auth.account$.value
      const infoUrl = encodeURIComponent(`${config.ACCOUNT_BASE_URL}/info`)
      const accountUrl = `${config.ACCOUNT_BASE_URL}/login?token=${
        account?.token ?? ''
      }&redirect_uri=${infoUrl}`
      location.href = accountUrl
    }
  },
}
